package android.com.app;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class rowEdit extends Activity{

   private String titArg;
   private String tagArg;
   private int idArg;
   private EditText mTitleText;
   private TextView mBodyText;
   private listenerClass lstCl=new listenerClass();

   @Override
  protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.rowedit);
        Bundle extras=getIntent().getExtras();
        titArg=extras.getString("title");
        tagArg=extras.getString("tag");
        idArg=extras.getInt("id");
    
        mTitleText = (EditText) findViewById(R.id.title2);
        mBodyText= (TextView) findViewById(R.id.tv2);
        Button confirmButton = (Button) findViewById(R.id.confirm2);
        Button confirmButton1 = (Button) findViewById(R.id.confirm3);
        
        mTitleText.setText(tagArg);
        mBodyText.setText("Clear the tag and press OK to delete it!!");
        confirmButton.setOnClickListener(lstCl);
        confirmButton1.setOnClickListener(new View.OnClickListener() {
         public void onClick(View view) {
            setResult(RESULT_OK); 
         finish();
        }
    });
    }


 class listenerClass implements OnClickListener {

 private int clkCnt=0;

 public void onClick(View view) {
 Log.i("Debug", mTitleText.getText().toString());
            if(mTitleText.getText().toString().equals("")) {
            if(clkCnt++==0) {
            mBodyText.setText("Do you want to clear the tag?? If yes, Click OK");
            return;
           }
            else {
            fillBundle(null);
           }
           }
            else {
            fillBundle(mTitleText.getText().toString());
           }
         }

 public void fillBundle(String newtag) {

    Bundle bundle = new Bundle();
 bundle.putString("newtag", newtag);
 bundle.putString("title", titArg);
 bundle.putInt("oldtag", idArg);
            Intent mIntent = new Intent();
            mIntent.putExtras(bundle); 
            setResult(RESULT_OK, mIntent); 
         finish();
}

}
}
 